package cn.edu.suda.catalina.health;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioGroup;

import java.util.HashMap;
import java.util.Map;

import cn.edu.suda.catalina.util.SharedPreferencesUtil;


/**
 * A simple {@link Fragment} subclass.
 * Use the {@link TenFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class TenFragment extends Fragment {

    private Map<String, Integer> map;

    public TenFragment() {}

    public static TenFragment newInstance() {
        return new TenFragment();
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_ten, container, false);

        map = new HashMap<>();
        map.put("X10", -3);

        RadioGroup radioGroup = (RadioGroup) rootView.findViewById(R.id.ten_radioGroup);
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.ten_one:
                        map.put("X10", -3);
                        break;
                    case R.id.ten_two:
                        map.put("X10", 0);
                        break;
                    case R.id.ten_three:
                        map.put("X10", 2);
                        break;
                    default:
                        break;
                }
            }
        });

        return rootView;
    }

    @Override
    public void onPause() {
        super.onPause();
        SharedPreferencesUtil.editSharedPreferences(getContext(), map);
    }

}
